package fz.vrd.library.page;

import android.app.Activity;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.provider.Settings;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import fz.vrd.library.log.LogFactory;

import fz.vrd.library.permissions.PermissionsManage;
import fz.vrd.library.utils.AppUtils;
import fz.vrd.library.utils.StringUtils;

/**
 * <b>名称： 父类activity和fragment的一些基础使用类 <br/>
 * <b>创建人： VinRichard <br/>
 * <b>时间： 2021/6/10 11:12 <br/>
 * <b>备注：{ } <br/>
 */
public class PageImp extends Page {

    FragmentActivity activity;

    Fragment fragment;


    public PageImp(FragmentActivity activity) {
        if (activity == null) {
            throw new NullPointerException("初始化activity为null了");
        }
        this.activity = activity;

    }

    public PageImp(Fragment fragment) {
        if (fragment == null) {
            throw new NullPointerException("初始化fragment为null了");
        }
        this.fragment = fragment;
        this.activity = fragment.getActivity();
    }


    @Override
    public FragmentActivity getActivity() {

        return activity;
    }

    @Override
    public Context getContext() {

        return activity;
    }

    @Override
    public void backPage() {
        if (activity != null && !activity.isDestroyed()) {
            if (fragment != null) {
                if (fragment.getParentFragmentManager().getBackStackEntryCount() > 0) {
                    fragment.getParentFragmentManager().popBackStack();
                } else if (activity.getSupportFragmentManager().getBackStackEntryCount() > 0) {
                    activity.getSupportFragmentManager().popBackStack();
                } else {
                    activity.finish();
                }
            } else {
                activity.finish();
            }
        }
    }



}
